Override ProcessOutputLine.ToString() to return Content#128359
Merged
Conversation
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/e307eeed-5d89-42ae-b7a7-bc9ca029caaa Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix ProcessOutputLine.ToString to return Content
Override ProcessOutputLine.ToString() to return Content
May 19, 2026
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process |
This was referenced May 19, 2026
Open
adamsitnik
reviewed
May 19, 2026
Member
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please address my feedback
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/2df5bc28-d920-4c80-8a65-1221ed53310e Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
reviewed
May 19, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes System.Diagnostics.ProcessOutputLine to override ToString() so it returns the line’s text content, aligning default formatting (e.g., Console.WriteLine(line)) with typical expectations for “line” types.
Changes:
- Override
ProcessOutputLine.ToString()to returnContent. - Update the
System.Diagnostics.Processreference assembly to include theToString()override. - Add unit tests validating
ToString()behavior for populated and default struct cases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/System.Diagnostics.Process/tests/ProcessStreamingTests.cs | Adds tests covering ProcessOutputLine.ToString() for common inputs and default struct behavior. |
| src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessOutputLine.cs | Implements ToString() override returning Content. |
| src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs | Adds the ToString() override to the public API contract in the reference assembly. |
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/8e21291c-96b8-472e-9cba-a227421ce26f Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ProcessOutputLine.ToString()returned the default type name ("System.Diagnostics.ProcessOutputLine"), makingConsole.WriteLine(line)useless without explicitly accessing.Content.This adds a
ToString()override returningContent ?? string.Empty, following the same pattern used byStringSegmentandStringValuesinMicrosoft.Extensions.Primitives. The?? string.Emptyguard ensures the method never returnsnullfor a default-initialized struct, which aligns with the .NET docs requirement thatToString()should not returnnullorstring.Emptyas a meaningful value in normal usage:Changes
ProcessOutputLine.cs: Addedpublic override string ToString() => Content ?? string.Empty;ref/System.Diagnostics.Process.cs: AddedToString()to the reference assemblyProcessStreamingTests.cs: Added unit tests forToString()behavior; default struct case assertsstring.Empty